#pragma once
#include "Node.h"

namespace Strumpan
{
	template < class T >
	class Queue
	{
	private:
		Node<T> *head;
		Node<T> *tail;
	public:

		Queue(void)
		{
			head = tail = nullptr;
		}

		~Queue(void)
		{
			Node<T> *n = head;
			Node<T> *d = n;

			while( n != nullptr )
			{
				d = n;
				n = n->next;
				delete d;
			}
		}


		void Push_Back( T info )
		{
			if( tail == nullptr ) // empty Queue
				head = tail = new Node<T>( info );
			else if( head == tail ) // one node in Queue
			{
				head->next = tail;
				Node<T> *n = new Node<T>(info);
				tail->next = n;
				n->previous = tail;
				tail = n;
			}
			else
			{
				Node<T> *n = new Node<T>(info);
				tail->next = n;
				n->previous = tail;
				tail = n;
			}
		}

		Node<T> Pop( )
		{
			Node<T> n;
			if( head == nullptr ) // empty Queue
				return false;
			else if( head ) 
			{
				n = *head;
				head->~Node(); 
				head = head->next;
				
			}
			return n;
		}


	};

}

